import sys
sys.path.append('.')
import os

from util.PATH import PATH
from src.data_helper import DataHelper
import numpy as np


def func(dataset_name):
	path = PATH(dataset_name)
	data_helper = DataHelper(path)
	bug_msg_all, _ = data_helper.get_msg_all()      # In fact, 可以将这些变量一起

	products = []
	components = []
	product_components = []		# 已有的产品和组件组合

	for bugid, value in bug_msg_all.items():
		product = value[3]
		component = value[4]
		if product not in products:
			products.append(product)
		if component not in components:
			components.append(component)
		if '{}_{}'.format(product, component) not in product_components:
			product_components.append('{}_{}'.format(product, component))

	products = sorted(products)
	components = sorted(components)
	product_components = sorted(product_components)

	with open(os.path.join(path.root, 'products.txt'), 'w') as writer:
		for x in products:
			writer.write('{}\n'.format(x))
	with open(os.path.join(path.root, 'components.txt'), 'w') as writer:
		for x in components:
			writer.write('{}\n'.format(x))
	with open(os.path.join(path.root, 'product_components.txt'), 'w') as writer:
		for x in product_components:
			writer.write('{}\n'.format(x))

if __name__ == "__main__":
	for name in ['Mozilla', 'Netbeans', 'GCC', 'Eclipse', 'OpenOffice']:
		print(name)
		func(name)



